home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5104 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with pointer alignment
  5. Date: Thu, 08 Feb 1996 14:58:31 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <3119F377.369F@cmt.lpr.mail.carel.fi>
  8. References: <4fb0op$8l8@hermes.louisville.edu>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  14.  
  15. Alan Wild wrote:
  16. > I am having a small problem with pointer alignment in a library I am
  17. > developing. lint reports:
  18. > "queue.c", line 13: warning: possible pointer alignment problem, op CAST
  19. > And the code is as follows:
  20. > struct  dataChain {
  21. >         ORD64           dataf;
  22. >         ORD64           be;
  23. >         int             cycle;
  24. > struct  dataChain       *next;
  25. > };
  26. > typedef struct dataChain queueentry;
  27. > void Append ( queueentry new, queue *Q ) {
  28. >         queueentry *temp = (queueentry *)malloc( sizeof( queueentry ) );
  29. >         temp->dataf = new.dataf;
  30. >         temp->be= new.be;
  31. >         temp->cycle = new.cycle;
  32. >         temp->next = new.next;
  33. >         AppendData ( temp, Q );
  34. > }
  35. > The line in error is the malloc statement.  What have I done
  36. > wrong/dangerously?  I would like to correct this if at all possible.
  37. > This is the only pententially problematic warning in my code and I would
  38. > like to avoid any problems.  :)
  39. > Note:  I have checked through several books and the C FAQ, but I haven't
  40. > seen anything.  My co-workers also did not have a clue about this one.
  41. > I am developing on anIBM rs6000 running AIX 3.2.5.  I am using the
  42. > native version of lint.
  43.  
  44. If the compiler uses 8-byte alignment and sizeof(int) is 32 bits, there may be 4 bytes 
  45. padding in between 'cycle' and 'next' in the structure. This is perhaps the reason of the 
  46. warning. (I take it ORD64 means a 64-bit variable type.) In this case, it should not 
  47. matter, but if the 'Append' function is to be called outside of this compilation module 
  48. (eg. it may reside in a library), and the calling module has been compiled with different 
  49. padding, this will lead to problems, since 'next' will not get properly initialized inside 
  50. Append since the actual byte offset inside 'new' will be different.
  51.  
  52. Later,
  53.  AriL
  54. -- 
  55. All my opinions are mine and mine alone.
  56.